<?php
/**
 * Moduleadmin_Data_Deletemodule
 * delete current module
 * @author Adrian Stolarski
 */
class Moduleadmin_Data_Deletemodule implements Moduleadmin_Data_Mainable, 
        Moduleadmin_Data_Preparable, Moduleadmin_Data_Redirectable{
    
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    /**
     *
     * @var type $database_query
     * database query handler
     */
    public $database_query;
    /**
     *
     * @var type $redirect_action
     * redirect action handler
     */
    public $redirect_action;
    
    /**
     * constructor()
     */
    public function __construct() {
        $this->database = new Core_Driver_MysqlImproved;
    }
    
    public function main(array $variables = null) {
        //var_dump($variables);
        //die();
        $this->database->connect();
        foreach($variables as $key => $value){
            $variables['$key'] = $this->database->escape($value);
        }
        //var_dump($variables);
        //die();
        $this->prepare_query($variables);
        //echo $this->database_query;
        $this->database->prepare($this->database_query);
        $this->database->query();
        $this->database->dataOperations();
        $this->redirect_action($variables);
    }
    /**
     * prepare_query()
     * prepare database query
     * 
     * @param array $variables
     */
    public function prepare_query(array $variables = null) {
        //var_dump($variables);
        //die();
        $this->database_query = "DELETE"
                . " FROM "
                . "page_module"
                . " WHERE "
                . "module_name='"
                .$variables['module_name']."';";
    }
    
    /**
     * redirect_action()
     * redirect module list action
     * 
     * @param array $variables
     */
    public function redirect_action(array $variables = null) {
        $this->redirect_action = new Moduleadmin_Data_Modulelistredirect;
        $this->redirect_action->main($variables);
    }

}
